package com.google.code.avajhelpdesk.pages.issues;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.code.avajhelpdesk.entities.Issue;
import com.google.code.avajhelpdesk.entities.Issue.IssuePriority;
import com.google.code.avajhelpdesk.pages.BasePage;
import com.google.code.avajhelpdesk.persistence.IGenericDAO;

public class CreateIssue extends BasePage {

	private static final Logger logger = LoggerFactory.getLogger(CreateIssue.class);
	
	@SpringBean
	private IGenericDAO genericDAO;
	
	private Issue newIssue;
	
	public CreateIssue() {
		InjectorHolder.getInjector().inject(this);
		
		newIssue = new Issue();
		
		Form form = new Form("newIssue") {
			@Override
			protected void onSubmit() {
				logger.debug("Issue created");
				CreateIssue.this.genericDAO.merge(newIssue);
				
			}
		};
		
		
		add(form);

		TextField textField = new TextField("title", new PropertyModel(newIssue, "title"));
		form.add(textField);
		
		form.add(new TextArea("description", new PropertyModel(newIssue, "description")));
		
		List<IssuePriority> choices = Arrays.asList(Issue.IssuePriority.values());
		
		form.add(new DropDownChoice("priority", new PropertyModel(newIssue, "priority"), choices));
		
	}
	
	@Override
	protected String getPageTitle() {
		return "Create issue";
	}

}
